package com.hspedu.JUCTest;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/3/15
 * @time 19:57
 */
public class AtomicIntegerTest {

    static AtomicInteger atomicInteger = new AtomicInteger();

    public static void main(String[] args) {

        for (int i = 0; i < 200; i++) {
            new Thread(new Runnable(){
                @Override
                public void run() {
                    try {
                        Thread.sleep(20);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    atomicInteger.getAndIncrement();
                }
            }).start();
        }

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(atomicInteger.get());

    }
}
